package controller;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import modelo.Funcionario;
import modelo.Reserva;
import modelo.SalaReuniao;
import service.FuncionarioService;
import service.ReservaService;
import service.SalaReuniaoService;

@Named
@ViewScoped
public class ReservaController implements Serializable {

	private static final long	serialVersionUID	= 2966029106096733501L;
	
	private Reserva reserva;
	private List<Reserva> listReservas;
	private Funcionario funcionario;
	private Long idFuncionarioSelecionado;
	private SalaReuniao salaReuniao;
	private Long idSalaReuniao;
	
	@Inject
	private ReservaService reservaService;
	
	@Inject
	private FuncionarioService funcionarioService;
	
	@Inject
	private SalaReuniaoService salaReuniaoService;
	
	public ReservaController() {

	}

	@PostConstruct
	public void init() {
		pesquisarReservas();
		reserva = new Reserva();
	}

	public String salvar() {
		this.reserva.setFuncionario(funcionarioService.recuperarPorId(idFuncionarioSelecionado));
		this.reserva.setSalaReuniao(salaReuniaoService.recuperarPorId(idSalaReuniao));
		reservaService.persistir(reserva);
		return "";
	}

	public String editar() {
		reservaService.editar(reserva);
		return "";
	}

	public String excluir() {
		reservaService.remover(reserva);
		return null;
	}

	public void pesquisarReservas() {
		setListReservas(reservaService.recuperarTodos());
	}
	
	public List<Funcionario> getListaFuncionarios(){
		return funcionarioService.recuperarTodos();
	}
	
	public List<SalaReuniao> getListaSalasReuniao(){
		return salaReuniaoService.recuperarTodos();
	}
	
	public String formataData(Date date){
		return "";//+date.getDay()+"/"+date.getMonth()+"/"+date.getYear();
	}
	
	//getters and setters
	
	public Reserva getReserva() {
		return reserva;
	}

	public void setReserva(Reserva reserva) {
		this.reserva = reserva;
	}

	public List<Reserva> getListReservas() {
		return listReservas;
	}

	public void setListReservas(List<Reserva> listReservas) {
		this.listReservas = listReservas;
	}

	public Funcionario getFuncionario() {
		return funcionario;
	}

	public void setFuncionario(Funcionario funcionario) {
		this.funcionario = funcionario;
	}

	public Long getIdFuncionarioSelecionado() {
		return idFuncionarioSelecionado;
	}

	public void setIdFuncionarioSelecionado(Long idFuncionarioSelecionado) {
		this.idFuncionarioSelecionado = idFuncionarioSelecionado;
	}

	public SalaReuniao getSalaReuniao() {
		return salaReuniao;
	}

	public void setSalaReuniao(SalaReuniao salaReuniao) {
		this.salaReuniao = salaReuniao;
	}

	public Long getIdSalaReuniao() {
		return idSalaReuniao;
	}

	public void setIdSalaReuniao(Long idSalaReuniao) {
		this.idSalaReuniao = idSalaReuniao;
	}

	public ReservaService getReservaService() {
		return reservaService;
	}

	public void setReservaService(ReservaService reservaService) {
		this.reservaService = reservaService;
	}

	public FuncionarioService getFuncionarioService() {
		return funcionarioService;
	}

	public void setFuncionarioService(FuncionarioService funcionarioService) {
		this.funcionarioService = funcionarioService;
	}

	public SalaReuniaoService getSalaReuniaoService() {
		return salaReuniaoService;
	}

	public void setSalaReuniaoService(SalaReuniaoService salaReuniaoService) {
		this.salaReuniaoService = salaReuniaoService;
	}

}
